<?php

namespace Common\Model;

use Think\Model;

class PatientTestModel extends Model {

    protected $tableName = 'patient_test';

    protected $_validate = array(
        ['patient_id', 'require', 'patient_id 需要提供', self::MUST_VALIDATE],
        ['test_name', 'checkTestName', '测试名称需要填写', self::MUST_VALIDATE, 'callback'],
        ['test_result','require','test_result必须',self::MUST_VALIDATE],
        ['test_result','checkMedicinelist','测试结果需为json格式',self::MUST_VALIDATE,'callback']
    );

    protected $_auto = array(
        ['create_time', 'time', self::MODEL_INSERT, 'function'],
        ['test_result','getJson',self::MODEL_BOTH,'callback']
    );

    public function checkTestName($name){
        if(!in_array($name,[
            'iss',
            'rems',
            'nihss',
            'crmas',
            'xxnt',
            'gcs'
        ])){
            return false;
        }else{

            return true;
        }
    }

    public function checkMedicinelist($list) {
        if( json_decode(html_entity_decode($list)) == null ){
            return false;
        }
        return true;
    }

    public function getJson($list){
        return html_entity_decode($list);
    }
}